

<!DOCTYPE html>
<html lang="zh-CN" data-default-color-scheme=&#34;auto&#34;>



<head>
  <meta charset="UTF-8">
  <link rel="apple-touch-icon" sizes="76x76" href="/img/zoro.jpg">
  <link rel="icon" href="/img/zoro.jpg">
  <meta name="viewport"
        content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  
  <meta name="theme-color" content="#efb9b9">
  <meta name="description" content="">
  <meta name="author" content="AgoniLay">
  <meta name="keywords" content="">
  
  <title>npm笔记 - AgoniLay的博客</title>

  <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/css/bootstrap.min.css" />


  <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/github-markdown-css@4.0.0/github-markdown.min.css" />
  <link  rel="stylesheet" href="/lib/hint/hint.min.css" />

  
    
    
      
      <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/highlight.js@10.7.2/styles/arta.min.css" />
    
  

  
    <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@3.5.7/dist/jquery.fancybox.min.css" />
  



<!-- 主题依赖的图标库，不要自行修改 -->

<link rel="stylesheet" href="//at.alicdn.com/t/font_1749284_ba1fz6golrf.css">



<link rel="stylesheet" href="//at.alicdn.com/t/font_1736178_kmeydafke9r.css">


<link  rel="stylesheet" href="/css/main.css" />

<!-- 自定义样式保持在最底部 -->

  
<link rel="stylesheet" href="/css/scroller.css">
<link rel="stylesheet" href="/css/bynode.css">
<link rel="stylesheet" href="/css/mouse.css">



  <script id="fluid-configs">
    var Fluid = window.Fluid || {};
    var CONFIG = {"hostname":"agonilay.github.io","root":"/","version":"1.8.11","typing":{"enable":true,"typeSpeed":150,"cursorChar":"❤","loop":false},"anchorjs":{"enable":true,"element":"h1,h2,h3,h4,h5,h6","placement":"right","visible":"hover","icon":""},"progressbar":{"enable":true,"height_px":3,"color":"#29d","options":{"showSpinner":false,"trickleSpeed":100}},"copy_btn":true,"image_zoom":{"enable":true,"img_url_replace":["",""]},"toc":{"enable":true,"headingSelector":"h1,h2,h3,h4,h5,h6","collapseDepth":0},"lazyload":{"enable":true,"loading_img":"/img/loading2.gif","onlypost":false,"offset_factor":2},"web_analytics":{"enable":false,"baidu":null,"google":null,"gtag":null,"tencent":{"sid":null,"cid":null},"woyaola":null,"cnzz":null,"leancloud":{"app_id":null,"app_key":null,"server_url":null}},"search_path":"/local-search.xml"};
  </script>
  <script  src="/js/utils.js" ></script>
  <script  src="/js/color-schema.js" ></script>
<meta name="generator" content="Hexo 5.4.0"></head>


<body>
  <header style="height: 70vh;">
    <nav id="navbar" class="navbar fixed-top  navbar-expand-lg navbar-dark scrolling-navbar">
  <div class="container">
    <a class="navbar-brand"
       href="/">&nbsp;<strong>AgoniLay</strong>&nbsp;</a>

    <button id="navbar-toggler-btn" class="navbar-toggler" type="button" data-toggle="collapse"
            data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <div class="animated-icon"><span></span><span></span><span></span></div>
    </button>

    <!-- Collapsible content -->
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav ml-auto text-center">
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/">
                <i class="iconfont icon-home-fill"></i>
                首页
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item dropdown">
              <a class="nav-link dropdown-toggle" target="_self" role="button"
                 data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                <i class="iconfont icon-bookmark"></i>
                索引
              </a>
              <div class="dropdown-menu" aria-labelledby="navbarDropdown">
                
                  
                  
                  
                  <a class="dropdown-item" href="/archives/">
                    <i class="iconfont icon-archive-fill"></i>
                    归档
                  </a>
                
                  
                  
                  
                  <a class="dropdown-item" href="/categories/">
                    <i class="iconfont icon-category-fill"></i>
                    分类
                  </a>
                
                  
                  
                  
                  <a class="dropdown-item" href="/tags/">
                    <i class="iconfont icon-tags-fill"></i>
                    标签
                  </a>
                
              </div>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/about/">
                <i class="iconfont icon-user-fill"></i>
                关于
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/links/">
                <i class="iconfont icon-link-fill"></i>
                友链
              </a>
            </li>
          
        
          
        
          <li class="nav-item" id="search-btn">
            <a class="nav-link" target="_self" data-toggle="modal" data-target="#modalSearch">&nbsp;<i
                class="iconfont icon-search"></i>&nbsp;</a>
          </li>
        
        
          <li class="nav-item" id="color-toggle-btn">
            <a class="nav-link" target="_self">&nbsp;<i
                class="iconfont icon-dark" id="color-toggle-icon"></i>&nbsp;</a>
          </li>
        
      </ul>
    </div>
  </div>
</nav>

    <div class="banner" id="banner" parallax=true
         style="background: url('/img/zoro2.jpg') no-repeat center center;
           background-size: cover;">
      <div class="full-bg-img">
        <div class="mask flex-center" style="background-color: rgba(0, 0, 0, 0.3)">
          <div class="page-header text-center fade-in-up">
            <span class="h3" id="subtitle" title="npm笔记">
              
            </span>

            
              <div class="mt-3">
  
    <span class="post-meta mr-2">
      <i class="iconfont icon-author" aria-hidden="true"></i>
      AgoniLay
    </span>
  
  
    <span class="post-meta">
      <i class="iconfont icon-date-fill" aria-hidden="true"></i>
      <time datetime="2021-07-29 23:30" pubdate>
        2021年7月29日 晚上
      </time>
    </span>
  
</div>

<div class="mt-1">
  

  
    
    <span class="post-meta mr-2">
      <i class="iconfont icon-clock-fill"></i>
      
      
      32
       分钟
    </span>
  

  
  
    
      <!-- 不蒜子统计文章PV -->
      <span id="busuanzi_container_page_pv" style="display: none">
        <i class="iconfont icon-eye" aria-hidden="true"></i>
        <span id="busuanzi_value_page_pv"></span> 次
      </span>
    
  
</div>

            
			
			
          </div>

          
        </div>
      </div>
    </div>
  </header>

  <main>
    
      

<div class="container-fluid nopadding-x">
  <div class="row nomargin-x">
    <div class="d-none d-lg-block col-lg-2"></div>
    <div class="col-lg-8 nopadding-x-md">
      <div class="container nopadding-x-md" id="board-ctn">
        <div class="py-5" id="board">
          <article class="post-content mx-auto">
            <!-- SEO header -->
            <h1 style="display: none">npm笔记</h1>
            
            <div class="markdown-body">
              <h2 id="一、NPM-简介"><a href="#一、NPM-简介" class="headerlink" title="一、NPM 简介"></a>一、NPM 简介</h2><h3 id="1-1-是什么"><a href="#1-1-是什么" class="headerlink" title="1.1 是什么"></a>1.1 是什么</h3><p>npm（node package manager）：是一个命令行工具</p>
<h3 id="1-2-能干嘛"><a href="#1-2-能干嘛" class="headerlink" title="1.2 能干嘛"></a>1.2 能干嘛</h3><p>下载 node 所需第三方模块，npm 是NodeJS项目模块管理工具</p>
<h3 id="1-3-去哪儿下"><a href="#1-3-去哪儿下" class="headerlink" title="1.3 去哪儿下"></a>1.3 去哪儿下</h3><p>安装 Node.JS 自带 npm 所以不用重新安装，直接使用。</p>
<p>检查版本，是否安装：</p>
<figure class="highlight php"><table><tr><td class="gutter hljs"><div class="hljs code-wrapper"><pre><span class="line">1</span><br></pre></div></td><td class="code"><div class="hljs code-wrapper"><pre><code class="hljs php">npm -v<br></code></pre></div></td></tr></table></figure>

<h2 id="二、NPM-语法"><a href="#二、NPM-语法" class="headerlink" title="二、NPM 语法"></a>二、NPM 语法</h2><h4 id="命令"><a href="#命令" class="headerlink" title="命令"></a>命令</h4><ul>
<li>查看：npm list     list 可以简写为 ls</li>
<li>安装：npm install 模块 或 模块@版本号 [安装可选参数]     install 可以简写为 i</li>
<li>卸载：npm uninstall 模块</li>
</ul>
<h4 id="安装参数"><a href="#安装参数" class="headerlink" title="安装参数"></a>安装参数</h4><ul>
<li>–save                记录生产环境所需模块（默认） 简写为 -S</li>
<li>–save-dev        记录开发环境所需模块 简写为 -D</li>
<li>-g                       该模块可在命令行运行（global）</li>
</ul>
<p>多学一招：</p>
<figure class="highlight php"><table><tr><td class="gutter hljs"><div class="hljs code-wrapper"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></div></td><td class="code"><div class="hljs code-wrapper"><pre><code class="hljs php"><span class="hljs-comment">// 都安装</span><br>npm install<br><span class="hljs-comment">// 只安装生产环境</span><br>npm install --production<br><span class="hljs-comment">// 看全局目录所在位置</span><br>npm config <span class="hljs-keyword">list</span><br></code></pre></div></td></tr></table></figure>

<h2 id="三、NPM-使用"><a href="#三、NPM-使用" class="headerlink" title="三、NPM 使用"></a>三、NPM 使用</h2><h3 id="3-1-初体验"><a href="#3-1-初体验" class="headerlink" title="3.1 初体验"></a>3.1 初体验</h3><p>初始化 npm</p>
<figure class="highlight php"><table><tr><td class="gutter hljs"><div class="hljs code-wrapper"><pre><span class="line">1</span><br></pre></div></td><td class="code"><div class="hljs code-wrapper"><pre><code class="hljs php">npm init -y<br></code></pre></div></td></tr></table></figure>

<p>安装 MIME 模块</p>
<figure class="highlight php"><table><tr><td class="gutter hljs"><div class="hljs code-wrapper"><pre><span class="line">1</span><br></pre></div></td><td class="code"><div class="hljs code-wrapper"><pre><code class="hljs php">npm install mime<br></code></pre></div></td></tr></table></figure>

<p>使用</p>
<figure class="highlight js"><table><tr><td class="gutter hljs"><div class="hljs code-wrapper"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></div></td><td class="code"><div class="hljs code-wrapper"><pre><code class="hljs js"><span class="hljs-comment">// 1. 引入第三方模块 mime （判断文件 MIME 类型）</span><br><span class="hljs-keyword">var</span> mime = <span class="hljs-built_in">require</span>(<span class="hljs-string">&#x27;mime&#x27;</span>)<br><span class="hljs-comment">// 2. 使用</span><br><span class="hljs-keyword">var</span> img = <span class="hljs-string">&#x27;xxx.png&#x27;</span><br><span class="hljs-comment">// 获取MIME类型</span><br><span class="hljs-built_in">console</span>.log(mime.getType(img));                    <span class="hljs-comment">// ⇨ &#x27;image/png&#x27;</span><br><span class="hljs-comment">// 获取文件扩展名</span><br><span class="hljs-built_in">console</span>.log(mime.getExtension(mime.getType(img))); <span class="hljs-comment">// ⇨ &#x27;null&#x27;</span><br></code></pre></div></td></tr></table></figure>

<h4 id="全局使用"><a href="#全局使用" class="headerlink" title="全局使用"></a>全局使用</h4><p>查看全局目录，命令行输入：</p>
<figure class="highlight php"><table><tr><td class="gutter hljs"><div class="hljs code-wrapper"><pre><span class="line">1</span><br></pre></div></td><td class="code"><div class="hljs code-wrapper"><pre><code class="hljs php">npm config <span class="hljs-keyword">list</span><br></code></pre></div></td></tr></table></figure>

<p>找到全局路径：</p>
<figure class="highlight php"><table><tr><td class="gutter hljs"><div class="hljs code-wrapper"><pre><span class="line">1</span><br></pre></div></td><td class="code"><div class="hljs code-wrapper"><pre><code class="hljs php">prefix = <span class="hljs-string">&quot;C:\\Users\\AgoniLay\\AppData\\Roaming\\npm&quot;</span><br></code></pre></div></td></tr></table></figure>

<p>安装全局：</p>
<figure class="highlight php"><table><tr><td class="gutter hljs"><div class="hljs code-wrapper"><pre><span class="line">1</span><br></pre></div></td><td class="code"><div class="hljs code-wrapper"><pre><code class="hljs php">npm install mime -g<br></code></pre></div></td></tr></table></figure>

<p>安装在生产环境中：</p>
<figure class="highlight php"><table><tr><td class="gutter hljs"><div class="hljs code-wrapper"><pre><span class="line">1</span><br></pre></div></td><td class="code"><div class="hljs code-wrapper"><pre><code class="hljs php">npm install mime --save<br></code></pre></div></td></tr></table></figure>

<figure class="highlight json"><table><tr><td class="gutter hljs"><div class="hljs code-wrapper"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></div></td><td class="code"><div class="hljs code-wrapper"><pre><code class="hljs json">&#123;<br>    <span class="hljs-attr">&quot;dependencies&quot;</span>: &#123;<br>        <span class="hljs-attr">&quot;mime&quot;</span>: <span class="hljs-string">&quot;^2.5.2&quot;</span><br>    &#125;,<br>&#125;<br></code></pre></div></td></tr></table></figure>

<p>安装在开发环境中：</p>
<figure class="highlight php"><table><tr><td class="gutter hljs"><div class="hljs code-wrapper"><pre><span class="line">1</span><br></pre></div></td><td class="code"><div class="hljs code-wrapper"><pre><code class="hljs php">npm install jquery --save-dev<br></code></pre></div></td></tr></table></figure>

<figure class="highlight json"><table><tr><td class="gutter hljs"><div class="hljs code-wrapper"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></div></td><td class="code"><div class="hljs code-wrapper"><pre><code class="hljs json">&#123;<br>    <span class="hljs-attr">&quot;devDependencies&quot;</span>: &#123;<br>        <span class="hljs-attr">&quot;jquery&quot;</span>: <span class="hljs-string">&quot;^3.6.0&quot;</span><br>    &#125;<br>&#125;<br></code></pre></div></td></tr></table></figure>

<p>仅安装生产环境中的依赖：</p>
<figure class="highlight php"><table><tr><td class="gutter hljs"><div class="hljs code-wrapper"><pre><span class="line">1</span><br></pre></div></td><td class="code"><div class="hljs code-wrapper"><pre><code class="hljs php">npm install --production<br></code></pre></div></td></tr></table></figure>

<h2 id="四、NPM-模块版本控制（了解）"><a href="#四、NPM-模块版本控制（了解）" class="headerlink" title="四、NPM 模块版本控制（了解）"></a>四、NPM 模块版本控制（了解）</h2><h3 id="科普软件版本含义："><a href="#科普软件版本含义：" class="headerlink" title="科普软件版本含义："></a>科普软件版本含义：</h3><ul>
<li>aplha版    - 内测版（功能不全，bug多）</li>
<li>beta版      - 公测版（功能不全，发骚友准备，依旧存在bug）</li>
<li>rc版           - 预览版（功能不再增减）</li>
<li>stable版    - 用户可用</li>
</ul>
<p>主版本号.次版本号.修改版本号</p>
<ul>
<li>^   ：用户使用该版本后，最多升级到【修改版】最新</li>
<li>～ ：用户使用该版本后，最多升级到【次版本】最新</li>
<li> *  ：用户使用该版本后，最多升级到最新版本</li>
</ul>
<h2 id="五、NPM-源管理"><a href="#五、NPM-源管理" class="headerlink" title="五、NPM 源管理"></a>五、NPM 源管理</h2><p>通过 npm 命令下载会到国外服务器获取</p>
<p>缺点：下载速度慢</p>
<p>解决：切换到国内服务器</p>
<h3 id="nrm"><a href="#nrm" class="headerlink" title="nrm"></a>nrm</h3><figure class="highlight php"><table><tr><td class="gutter hljs"><div class="hljs code-wrapper"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></div></td><td class="code"><div class="hljs code-wrapper"><pre><code class="hljs php"><span class="hljs-comment">// 安装</span><br>npm install nrm -g <br><span class="hljs-comment">// 查看  ls 为 list 缩写</span><br>nrm ls<br><span class="hljs-comment">// 切换服务器名</span><br>nrm <span class="hljs-keyword">use</span> 服务器名<br>// 测速<br><span class="hljs-title">nrm</span> <span class="hljs-title">test</span><br></code></pre></div></td></tr></table></figure>

<h2 id="六、NPM-自定义脚本命令（重点，难点）"><a href="#六、NPM-自定义脚本命令（重点，难点）" class="headerlink" title="六、NPM 自定义脚本命令（重点，难点）"></a>六、NPM 自定义脚本命令（重点，难点）</h2><p>通过修改 package.json 文件的 scripts 自定义脚本命令</p>
<p>必须严格遵循格式</p>
<figure class="highlight json"><table><tr><td class="gutter hljs"><div class="hljs code-wrapper"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></div></td><td class="code"><div class="hljs code-wrapper"><pre><code class="hljs json"><span class="hljs-string">&quot;scripts&quot;</span>: &#123;<br>    <span class="hljs-attr">&quot;test&quot;</span>: <span class="hljs-string">&quot;echo \&quot;Error: no test specified\&quot; &amp;&amp; exit 1&quot;</span>,<br>    <span class="hljs-attr">&quot;a&quot;</span>: <span class="hljs-string">&quot;echo 666&quot;</span>,<br>    <span class="hljs-attr">&quot;start&quot;</span>: <span class="hljs-string">&quot;node ./mime_text.js&quot;</span><br>&#125;,<br></code></pre></div></td></tr></table></figure>

<figure class="highlight php"><table><tr><td class="gutter hljs"><div class="hljs code-wrapper"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></div></td><td class="code"><div class="hljs code-wrapper"><pre><code class="hljs php">npm run a<br>    <span class="hljs-comment">// 666</span><br>npm start<br>    <span class="hljs-comment">// 运行</span><br></code></pre></div></td></tr></table></figure>

<h2 id="七、NPM-包自定义发布（能跟着笔记敲）"><a href="#七、NPM-包自定义发布（能跟着笔记敲）" class="headerlink" title="七、NPM 包自定义发布（能跟着笔记敲）"></a>七、NPM 包自定义发布（能跟着笔记敲）</h2><ol>
<li><p>自定义模块，创建文件夹，打开终端 cd 到该文件夹下 初始化</p>
<figure class="highlight php"><table><tr><td class="gutter hljs"><div class="hljs code-wrapper"><pre><span class="line">1</span><br></pre></div></td><td class="code"><div class="hljs code-wrapper"><pre><code class="hljs php">npm init -y<br></code></pre></div></td></tr></table></figure>

<p>index.js</p>
<figure class="highlight js"><table><tr><td class="gutter hljs"><div class="hljs code-wrapper"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></div></td><td class="code"><div class="hljs code-wrapper"><pre><code class="hljs js"><span class="hljs-keyword">var</span> fn = &#123;<br>    <span class="hljs-attr">name</span>: <span class="hljs-string">&#x27;phpopenfather&#x27;</span>,<br>    <span class="hljs-attr">school</span>: <span class="hljs-string">&#x27;php@itcast&#x27;</span>,<br>    <span class="hljs-attr">say</span>: <span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params"></span>) </span>&#123;<br>        <span class="hljs-built_in">console</span>.log(<span class="hljs-string">&#x27;悟空&#x27;</span>);<br>        <span class="hljs-keyword">return</span> un;<br>    &#125;<br>&#125;<br><br><span class="hljs-built_in">module</span>.exports = fn<br></code></pre></div></td></tr></table></figure></li>
<li><p>设置package</p>
<ul>
<li>name - 模块名</li>
<li>description - 描述</li>
<li>keywords - 关键词</li>
</ul>
<figure class="highlight json"><table><tr><td class="gutter hljs"><div class="hljs code-wrapper"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></div></td><td class="code"><div class="hljs code-wrapper"><pre><code class="hljs json">&#123;<br>    <span class="hljs-attr">&quot;name&quot;</span>: <span class="hljs-string">&quot;itcast-php-agonilay&quot;</span>,<br>    <span class="hljs-attr">&quot;version&quot;</span>: <span class="hljs-string">&quot;1.0.0&quot;</span>,<br>    <span class="hljs-attr">&quot;description&quot;</span>: <span class="hljs-string">&quot;this is demo2&quot;</span>,<br>    <span class="hljs-attr">&quot;main&quot;</span>: <span class="hljs-string">&quot;index.js&quot;</span>,<br>    <span class="hljs-attr">&quot;scripts&quot;</span>: &#123;<br>        <span class="hljs-attr">&quot;test&quot;</span>: <span class="hljs-string">&quot;echo \&quot;Error: no test specified\&quot; &amp;&amp; exit 1&quot;</span><br>    &#125;,<br>    <span class="hljs-attr">&quot;keywords&quot;</span>: [<span class="hljs-string">&quot;itcast&quot;</span>, <span class="hljs-string">&quot;phpdemo&quot;</span>],<br>    <span class="hljs-attr">&quot;author&quot;</span>: <span class="hljs-string">&quot;AgoniLay&quot;</span>,<br>    <span class="hljs-attr">&quot;license&quot;</span>: <span class="hljs-string">&quot;ISC&quot;</span><br>&#125;<br></code></pre></div></td></tr></table></figure></li>
<li><p>打开 <a target="_blank" rel="noopener" href="http://npmjs.com/">http://npmjs.com</a> 注册/登录 账号</p>
<p>本地登录提交（切记提交自己的包必须切换到国外服务器，下载再切换过来）</p>
<figure class="highlight php"><table><tr><td class="gutter hljs"><div class="hljs code-wrapper"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></div></td><td class="code"><div class="hljs code-wrapper"><pre><code class="hljs php"><span class="hljs-comment">// 切换到国外服务器</span><br>nrm <span class="hljs-keyword">use</span> <span class="hljs-title">npm</span><br>// 登录<br><span class="hljs-title">npm</span> <span class="hljs-title">login</span><br>	&gt;<span class="hljs-title">Username</span>: <span class="hljs-title">agonilay</span><br>	&gt;<span class="hljs-title">Password</span>:<br>	&gt;<span class="hljs-title">Email</span>: (<span class="hljs-title">this</span> <span class="hljs-title">IS</span> <span class="hljs-title">public</span>) 1394310259@<span class="hljs-title">qq</span>.<span class="hljs-title">com</span><br>	&gt;<span class="hljs-title">Logged</span> <span class="hljs-title">in</span> <span class="hljs-title">as</span> <span class="hljs-title">agonilay</span> <span class="hljs-title">on</span> <span class="hljs-title">https</span>://<span class="hljs-title">registry</span>.<span class="hljs-title">npmjs</span>.<span class="hljs-title">org</span>/.<br>// 提交<br><span class="hljs-title">npm</span> <span class="hljs-title">publish</span><br>    // 版本号不能是 1.0.0<br></code></pre></div></td></tr></table></figure></li>
<li><p>使用</p>
<figure class="highlight php"><table><tr><td class="gutter hljs"><div class="hljs code-wrapper"><pre><span class="line">1</span><br></pre></div></td><td class="code"><div class="hljs code-wrapper"><pre><code class="hljs php">npm i itcast-php-agonilay<br></code></pre></div></td></tr></table></figure>

<p>test.js</p>
<figure class="highlight js"><table><tr><td class="gutter hljs"><div class="hljs code-wrapper"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></div></td><td class="code"><div class="hljs code-wrapper"><pre><code class="hljs js"><span class="hljs-keyword">var</span> test = <span class="hljs-built_in">require</span>(<span class="hljs-string">&#x27;itcast-php-agonilay&#x27;</span>)<br><br><span class="hljs-built_in">console</span>.log(test);<br><span class="hljs-built_in">console</span>.log(test.name);<br>test.say();<br></code></pre></div></td></tr></table></figure>

<p>测试运行：</p>
<figure class="highlight php"><table><tr><td class="gutter hljs"><div class="hljs code-wrapper"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></div></td><td class="code"><div class="hljs code-wrapper"><pre><code class="hljs php">npm text.js<br>    <br><span class="hljs-comment">// 结果</span><br>&#123; name: <span class="hljs-string">&#x27;phpopenfather&#x27;</span>, school: <span class="hljs-string">&#x27;php@itcast&#x27;</span>, say: [<span class="hljs-function"><span class="hljs-keyword">Function</span>: <span class="hljs-title">say</span>] &#125;</span><br><span class="hljs-function"><span class="hljs-title">phpopenfather</span></span><br><span class="hljs-function">悟空</span><br></code></pre></div></td></tr></table></figure></li>
</ol>
<h2 id="nodemon-自动重启服务（第三方模块）"><a href="#nodemon-自动重启服务（第三方模块）" class="headerlink" title="nodemon 自动重启服务（第三方模块）"></a>nodemon 自动重启服务（第三方模块）</h2><h3 id="1、简介"><a href="#1、简介" class="headerlink" title="1、简介"></a>1、简介</h3><p>通过 nodemon 检测文件修改自动重启</p>
<h3 id="2、使用"><a href="#2、使用" class="headerlink" title="2、使用"></a>2、使用</h3><figure class="highlight php"><table><tr><td class="gutter hljs"><div class="hljs code-wrapper"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></div></td><td class="code"><div class="hljs code-wrapper"><pre><code class="hljs php"><span class="hljs-comment">// 安装</span><br>npm install nodemon --save-dev<br></code></pre></div></td></tr></table></figure>

<figure class="highlight php"><table><tr><td class="gutter hljs"><div class="hljs code-wrapper"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></div></td><td class="code"><div class="hljs code-wrapper"><pre><code class="hljs php"><span class="hljs-comment">// 运行</span><br>nodemon index.js<br></code></pre></div></td></tr></table></figure>

<h2 id="moment-日期处理模块（第三方模块）"><a href="#moment-日期处理模块（第三方模块）" class="headerlink" title="moment 日期处理模块（第三方模块）"></a>moment 日期处理模块（第三方模块）</h2><h3 id="1、简介-1"><a href="#1、简介-1" class="headerlink" title="1、简介"></a>1、简介</h3><p>自己封装模块或使用第三方模块（<a target="_blank" rel="noopener" href="http://momentjs.cn/%EF%BC%89">http://momentjs.cn/）</a></p>
<h3 id="2、使用-1"><a href="#2、使用-1" class="headerlink" title="2、使用"></a>2、使用</h3><ol>
<li><p>初始化项目</p>
<figure class="highlight php"><table><tr><td class="gutter hljs"><div class="hljs code-wrapper"><pre><span class="line">1</span><br></pre></div></td><td class="code"><div class="hljs code-wrapper"><pre><code class="hljs php">npm init -y<br></code></pre></div></td></tr></table></figure></li>
<li><p>安装 moment</p>
<figure class="highlight php"><table><tr><td class="gutter hljs"><div class="hljs code-wrapper"><pre><span class="line">1</span><br></pre></div></td><td class="code"><div class="hljs code-wrapper"><pre><code class="hljs php">npm install moment<br></code></pre></div></td></tr></table></figure></li>
<li><p>使用</p>
<figure class="highlight js"><table><tr><td class="gutter hljs"><div class="hljs code-wrapper"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></div></td><td class="code"><div class="hljs code-wrapper"><pre><code class="hljs js"><span class="hljs-keyword">var</span> moment = <span class="hljs-built_in">require</span>(<span class="hljs-string">&#x27;moment&#x27;</span>);<br>moment().format();<br></code></pre></div></td></tr></table></figure>

<p>需要使用哪种格式去 <a target="_blank" rel="noopener" href="http://momentjs.cn/">http://momentjs.cn/</a> 查看</p>
</li>
</ol>
<p>笔记CSDN博客地址：<a target="_blank" rel="noopener" href="https://blog.csdn.net/qq_58163927/article/details/118678133?spm=1001.2014.3001.5502">https://blog.csdn.net/qq_58163927/article/details/118678133?spm=1001.2014.3001.5502</a></p>

            </div>
            <hr>
            <div>
              <div class="post-metas mb-3">
                
                  <div class="post-meta mr-3">
                    <i class="iconfont icon-category"></i>
                    
                      <a class="hover-with-bg" href="/categories/%E5%B7%A5%E5%85%B7/">工具</a>
                    
                  </div>
                
                
                  <div class="post-meta">
                    <i class="iconfont icon-tags"></i>
                    
                      <a class="hover-with-bg" href="/tags/npm/">npm</a>
                    
                      <a class="hover-with-bg" href="/tags/nodemon/">nodemon</a>
                    
                  </div>
                
              </div>
              
                <p class="note note-warning">
                  
                    本博客所有文章除特别声明外，均为本人原创，转载请注明出处！
                  
                </p>
              
              
                <div class="post-prevnext">
                  <article class="post-prev col-6">
                    
                    
                      <a href="/2021/07/29/php%E7%AC%94%E8%AE%B0/">
                        <i class="iconfont icon-arrowleft"></i>
                        <span class="hidden-mobile">php笔记</span>
                        <span class="visible-mobile">上一篇</span>
                      </a>
                    
                  </article>
                  <article class="post-next col-6">
                    
                    
                      <a href="/2021/07/29/NodeJS%E7%AC%94%E8%AE%B0/">
                        <span class="hidden-mobile">NodeJS笔记</span>
                        <span class="visible-mobile">下一篇</span>
                        <i class="iconfont icon-arrowright"></i>
                      </a>
                    
                  </article>
                </div>
              
            </div>

            
          </article>
        </div>
      </div>
    </div>
    
      <div class="d-none d-lg-block col-lg-2 toc-container" id="toc-ctn">
        <div id="toc">
  <p class="toc-header"><i class="iconfont icon-list"></i>&nbsp;目录</p>
  <div class="toc-body" id="toc-body"></div>
</div>

      </div>
    
  </div>
</div>

<!-- Custom -->

  <div class="col-lg-7 mx-auto nopadding-x-md">
    <div class="container custom post-custom mx-auto">
      <img src="/img/agoni.gif" srcset="/img/loading2.gif" lazyload class="rounded mx-auto d-block mt-5" style="width:150px; height:150px;"> <h5 style="text-align: center; margin-top: 1rem;">谢谢您的光临噢！！！</h5> 
    </div>
  </div>


    

    
      <a id="scroll-top-button" href="#" role="button">
        <i class="iconfont icon-arrowup" aria-hidden="true"></i>
      </a>
    

    
      <div class="modal fade" id="modalSearch" tabindex="-1" role="dialog" aria-labelledby="ModalLabel"
     aria-hidden="true">
  <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header text-center">
        <h4 class="modal-title w-100 font-weight-bold">搜索</h4>
        <button type="button" id="local-search-close" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body mx-3">
        <div class="md-form mb-5">
          <input type="text" id="local-search-input" class="form-control validate">
          <label data-error="x" data-success="v"
                 for="local-search-input">关键词</label>
        </div>
        <div class="list-group" id="local-search-result"></div>
      </div>
    </div>
  </div>
</div>
    

    
  </main>

  <footer class="text-center mt-5 py-3">
  <div class="footer-content">
     <span>张宝文</span> <i class="iconfont icon-love"></i> <span>郑佳丽</span>  
	<!--《添加网站运行时间 -->
<br/>

<span id="timeDate">载入天数...</span><span id="times">载入时分秒...</span>
<script>
var now = new Date(); 

function createtime() {
    //此处修改你的建站时间或者网站上线时间
    var grt = new Date('07/28/2021 19:00:00');
    now.setTime(now.getTime() + 250);
    days = (now - grt) / 1000 / 60 / 60 / 24;

    dnum = Math.floor(days);
    hours = (now - grt) / 1000 / 60 / 60 - (24 * dnum);
    hnum = Math.floor(hours);
    if (String(hnum).length == 1) {
        hnum = "0" + hnum;
    }
    minutes = (now - grt) / 1000 / 60 - (24 * 60 * dnum) - (60 * hnum);
    mnum = Math.floor(minutes);
    if (String(mnum).length == 1) {
        mnum = "0" + mnum;
    }
    seconds = (now - grt) / 1000 - (24 * 60 * 60 * dnum) - (60 * 60 * hnum) - (60 * mnum);
    snum = Math.round(seconds);
    if (String(snum).length == 1) {
        snum = "0" + snum;
    }
    document.getElementById("timeDate").innerHTML = " 本站已各种夹缝中安全运行 " + dnum + " 天 ";
    document.getElementById("times").innerHTML = hnum + " 小时 " + mnum + " 分 " + snum + " 秒";
}
setInterval("createtime()", 250);
</script>

<!-- 添加网站运行时间》-->
  </div>
  
  <div class="statistics">
    
    

    
      
        <!-- 不蒜子统计PV -->
        <span id="busuanzi_container_site_pv" style="display: none">
            总访问量 
            <span id="busuanzi_value_site_pv"></span>
             次
          </span>
      
      
        <!-- 不蒜子统计UV -->
        <span id="busuanzi_container_site_uv" style="display: none">
            总访客数 
            <span id="busuanzi_value_site_uv"></span>
             人
          </span>
      
    
  </div>


  

  
</footer>


  <!-- SCRIPTS -->
  
  <script  src="https://cdn.jsdelivr.net/npm/nprogress@0.2.0/nprogress.min.js" ></script>
  <link  rel="stylesheet" href="https://cdn.jsdelivr.net/npm/nprogress@0.2.0/nprogress.min.css" />

  <script>
    NProgress.configure({"showSpinner":false,"trickleSpeed":100})
    NProgress.start()
    window.addEventListener('load', function() {
      NProgress.done();
    })
  </script>


<script  src="https://cdn.jsdelivr.net/npm/jquery@3.6.0/dist/jquery.min.js" ></script>
<script  src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.0/dist/js/bootstrap.min.js" ></script>
<script  src="/js/events.js" ></script>
<script  src="/js/plugins.js" ></script>

<!-- Plugins -->


  
    <script  src="/js/img-lazyload.js" ></script>
  



  



  <script  src="https://cdn.jsdelivr.net/npm/tocbot@4.12.3/dist/tocbot.min.js" ></script>



  <script  src="https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@3.5.7/dist/jquery.fancybox.min.js" ></script>



  <script  src="https://cdn.jsdelivr.net/npm/anchor-js@4.3.1/anchor.min.js" ></script>



  <script defer src="https://cdn.jsdelivr.net/npm/clipboard@2.0.8/dist/clipboard.min.js" ></script>



  <script  src="/js/local-search.js" ></script>



  <script defer src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js" ></script>




  <script  src="https://cdn.jsdelivr.net/npm/typed.js@2.0.12/lib/typed.min.js" ></script>
  <script src="https://sdk.jinrishici.com/v2/browser/jinrishici.js" charset="utf-8"></script>

  <script>
    function typing(id, title){
        var typed = new Typed('#' + id, {
            strings: [
              '  ',
              title + "&nbsp;",
            ],
            cursorChar: "❤",
            typeSpeed: 150,
            loop: false,
        });
        typed.stop();
        $(document).ready(function () {
            $(".typed-cursor").addClass("h2");
            typed.start();
        });
    }

    
        typing("subtitle", document.getElementById('subtitle').title)
    

  </script>













  
<script src="//cdn.jsdelivr.net/gh/bynotes/texiao/source/js/yinghua.js"></script>



<!-- 主题的启动项 保持在最底部 -->
<script  src="/js/boot.js" ></script>

</body>
</html>
